<template>
	<div class="accessory-order">
		<div>
			<label>{{$t('route.Device_Configuration')}}</label>
			<div></div>
			<button><img /><label>{{$t('route.Auxiliary_material_processing')}}</label></button>
		</div>

		<div>
			<div>
				<div>
					<!-- <el-cascader :options="options" @change="proLineChange" /> -->
				</div>
				<div class="div-handle-right">
					<el-button @click='jumpPage(0)'>{{$t('route.Add')}}</el-button>
					<!-- <el-button @click="downloadTempClick">导出模板</el-button>
					<el-upload ref="uploadFile" accept=".xlsx" :on-success="uploadSuccess"
						:action="BATCH_ARRANGE_ORDER_URL" :show-file-list='false' :limit="1">
						<el-button class="btn">批量导入</el-button>
					</el-upload> -->
					<el-button @click="searchClick">{{$t('route.search')}}</el-button>
					<input v-model="query.search" :placeholder="$t('route.Customer')" />
				</div>
			</div>

			<el-table class="table" :data="accessoryOrderList" style="width: 100%">
				<el-table-column prop="code" :label="$t('route.Item_No')" />
				<el-table-column prop="customer" :label="$t('route.Customer')" />
				<el-table-column prop="name" :label="$t('route.Name_of_Material')" />
				<el-table-column prop="paymentDate" :label="$t('route.order_date')" />
				<el-table-column prop="deliveryDate" :label="$t('route.date_of_delivery')" />
				<el-table-column prop="orderNum" :label="$t('route.total_quantity')" />
				<el-table-column prop="price" :label="$t('route.price')" />
				<el-table-column :label="$t('route.color')">
					<template #default="scope">
						{{ formatColor(scope.row) }}
					</template>
				</el-table-column>
				<el-table-column :label="$t('route.size')">
					<template #default="scope">
						{{ formatSize(scope.row) }}
					</template>
				</el-table-column>
				<el-table-column :label="$t('route.operate')" width="270">
					<template #default="scope">
						<el-button type="primary" @click='jumpPage(0, scope.row)'>{{$t('route.Editing')}}</el-button>
						<!-- <el-button type="primary" @click='jumpPage(0, scope.row)'>设备</el-button> -->
						<el-button type="danger" @click='deleteClick(scope.row.id)'>{{$t('route.Delete')}}</el-button>
					</template>
				</el-table-column>
			</el-table>
			<div class="pagination">
				<el-pagination style="float: right;" background @current-change="handlePageChange"
					:current-page="query.pageNum" :page-size="query.pageSize" layout="total, prev, pager, next"
					:total="query.total"></el-pagination>
			</div>
		</div>


	</div>
</template>

<script>
import http from "../../js/http/http.js";
import api from "../../js/http/api.js";
import CommonUtils from "../../js/common/common-utils.js";
import i18n from '../../i18n/index';
export default {
	data() {
		return {
			query: {
				pageNum: 1,
				pageSize: 13,
				total: 0,
				search: null,
				workshop: null,
				proLine: null
			},
			accessoryOrderList: [],
			BATCH_ARRANGE_ORDER_URL: null,
			options: [],

		};
	},
	methods: {
		formatColor(style) {
			var colorList = JSON.parse(style.colorList);
			var result = "";
			for (var item of colorList) {
				result += item + '/';
			}
			return result.substring(0, result.length - 1);
		},
		formatSize(style) {
			var sizeList = JSON.parse(style.sizeList);
			var result = "";
			for (var item of sizeList) {
				result += item + '/';
			}
			return result.substring(0, result.length - 1);
		},
		uploadSuccess(response, file, fileList) {
			console.log(i18n.global.t('route.Upload_succeeded'));
			this.$refs.uploadFile.clearFiles();
			console.log(response)
			if (response.resultCode == 0) {
				this.$message.success(i18n.global.t('route.Import_succeeded'));
				this.getAccessoryOrderList();
			} else {
				this.$message.error(response.resultMsg);
			}

		},
		downloadTempClick() {
			CommonUtils.download(api.BASE_URI + api.EXT_ARRANGE_ORDER_TEMP, i18n.global.t('route.Scheduling'));
		},
		searchClick() {
			this.query.pageNum = 1;
			this.getAccessoryOrderList();
		},
		getAccessoryOrderList() {
			http.post(api.GET_ACCESSORY_ORDER_LIST, {
				search: this.query.search,
				pageNum: this.query.pageNum,
				pageSize: this.query.pageSize,
				adminId: this.$store.state.user.id,
			}, data => {
				this.accessoryOrderList = data.data.accessoryOrderList;
				this.query.total = data.data.total;
			});
		},
		jumpPage(type, param1) {
			if (type == 0) {
				this.$store.commit('setAccessoryOrder', null);
				if (param1) {
					this.$router.push({
						name: 'add-accessory-order',
						params: {
							accessoryOrder: JSON.stringify(param1)
						}
					});
				} else {
					this.$router.push("/add-accessory-order");
				}

			} else if (type == 1) {
				this.$router.push({
					name: 'device-allocated',
					params: {
						arrangeOrder: JSON.stringify(param1)
					}
				})
			}
		},
		deleteClick(accessoryOrderId) {
			this.$confirm(i18n.global.t('route.fuliao'), i18n.global.t('route.reminder'), {
				confirmButtonText: i18n.global.t('route.sure'),
				cancelButtonText: i18n.global.t('route.cancel'),
				type: 'warning'
			}).then(() => {
				http.post(api.DELETE_ACCESSORY_ORDER, {
					accessoryOrderId: accessoryOrderId
				}, data => {
					this.$message.success(i18n.global.t('route.Delete_succeeded'));
					this.getAccessoryOrderList();
				});
			});

		},
		getPorLineRow() {
			http.post(api.GET_POR_LINE_ROW, {
				adminId: this.$store.state.user.id,
			}, data => {
				this.options = data.data;
			});
		},
		proLineChange(value) {
			this.query.workshop = value[0];
			this.query.proLine = value[1];
			this.getAccessoryOrderList();
		},
		handlePageChange(pageNum) {
			this.query.pageNum = pageNum;
			this.getAccessoryOrderList();
		},

	},
	created() {
		this.BATCH_ARRANGE_ORDER_URL = api.BASE_URI + api.BATCH_ARRANGE_ORDER + '?adminId=' + this.$store.state.user
			.id;
		this.getAccessoryOrderList();
		this.getPorLineRow();
	}
};
</script>
<style lang="scss" scoped>
.accessory-order {
	color: #444444;
	font-size: 18px;
	padding-right: 20px;
	height: calc(100vh - 100px);
	// overflow: scroll;
	scrollbar-width: none;
	/* firefox */
	-ms-overflow-style: none;
	/* IE 10+ */
	overflow-x: hidden;
	overflow-y: auto;

	>div {
		display: flex;
		flex-direction: row;
		margin-top: 20px;
		background-color: #ffffff;
		padding: 20px;
		border-radius: 5px;
	}

	>div:nth-of-type(1) {
		>label:nth-of-type(1) {
			font-weight: 600;
		}

		>div:nth-of-type(1) {
			width: 1px;
			background-color: #cccccc;
			height: 15px;
			margin: 0px 20px;
		}

		>button:nth-of-type(1) {
			background-image: url(../../assets/img/customer-1.png);
			background-repeat: no-repeat;
			background-size: 100% 100%;
			padding: 5px 10px;
			border: 0px;
			display: flex;
			color: #ffffff;
			flex-direction: row;
			align-items: center;
			font-weight: 800;

			>img {
				margin-right: 7px;
				width: 15px;
				height: 15px;
				content: url(../../assets/img/customer-2.png);
			}

		}
	}

	>div:nth-of-type(2) {
		flex-direction: column;

		>div:nth-of-type(1) {
			display: flex;
			flex-direction: row;
			align-items: center;

			.div-handle-right {
				flex: 1;
				flex-direction: row-reverse;
				text-align: right;
				display: flex;
				align-items: center;

				>input:nth-of-type(1) {
					border: 1px solid #eeeeee;
					font-size: 15px;
					width: 150px;
					padding: 5px 8px;
					outline: none;
				}

				>button {
					color: #A866FF;
					margin-left: 10px;
					padding: 4px 20px;
				}

				.btn {
					color: #A866FF;
					margin-left: 10px;
					padding: 4px 20px;
				}



			}
		}

		.table {
			margin-top: 20px;


		}

	}
}
</style>
